package com.fcy.teamwork.business.main.homepage.viewmodel

import androidx.lifecycle.ViewModel
import com.fcy.teamwork.App
import com.fcy.teamwork.pojo.ProjectInfo
import com.fcy.teamwork.pojo.TeamWorkResult
import com.fcy.teamwork.repo.RetrofitClient
import retrofit2.http.GET
import retrofit2.http.Query

interface MineService {
    @GET("/sms/project/involvedProjects")
    suspend fun loadMineProjects(@Query("userName") userName: String): TeamWorkResult<List<ProjectInfo>>
}

class MineVM : ViewModel() {
    private val service: MineService by lazy { RetrofitClient.getService() }
    suspend fun loadMineProjects(): List<ProjectInfo> {
        val res = service.loadMineProjects(App.person.personId)
        return if (res.isOk) {
            res.data
        } else {
            emptyList()
        }
    }
}